<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: samples/cpp/fitellipse.cpp</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">samples/cpp/fitellipse.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>An example using the fitEllipse technique</p>
<div class="fragment"><div class="line"><span class="comment">/********************************************************************************</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  This program is demonstration for ellipse fitting. Program finds</span></div><div class="line"><span class="comment"> *  contours and approximate it by ellipses using three methods.</span></div><div class="line"><span class="comment"> *  1: OpenCV&#39;s original method fitEllipse which implements Fitzgibbon 1995 method.</span></div><div class="line"><span class="comment"> *  2: The Approximate Mean Square (AMS) method fitEllipseAMS  proposed by Taubin 1991</span></div><div class="line"><span class="comment"> *  3: The Direct least square (Direct) method fitEllipseDirect proposed by Fitzgibbon1999.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  Trackbar specify threshold parameter.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  White lines is contours/input points and the true ellipse used to generate the data.</span></div><div class="line"><span class="comment"> *  1: Blue lines is fitting ellipses using openCV&#39;s original method.</span></div><div class="line"><span class="comment"> *  2: Green lines is fitting ellipses using the AMS method.</span></div><div class="line"><span class="comment"> *  3: Red lines is fitting ellipses using the Direct method.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *  Original Author:  Denis Burenkov</span></div><div class="line"><span class="comment"> *  AMS and Direct Methods Author:  Jasper Shemilt</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> ********************************************************************************/</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"></div><div class="line"><span class="keyword">class </span>canvas{</div><div class="line"><span class="keyword">public</span>:</div><div class="line">    <span class="keywordtype">bool</span> setupQ;</div><div class="line">    <a name="_a0"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point</a> origin;</div><div class="line">    <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point</a> corner;</div><div class="line">    <span class="keywordtype">int</span> minDims,maxDims;</div><div class="line">    <span class="keywordtype">double</span> <a name="a1"></a><a class="code" href="../../d6/d84/namespacecv_1_1quality_1_1quality__utils.html#ae55d1c89ff5761730174745401162743">scale</a>;</div><div class="line">    <span class="keywordtype">int</span> rows, cols;</div><div class="line">    <a name="_a2"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html">cv::Mat</a> img;</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> init(<span class="keywordtype">int</span> minD, <span class="keywordtype">int</span> maxD){</div><div class="line">        <span class="comment">// Initialise the canvas with minimum and maximum rows and column sizes.</span></div><div class="line">        minDims = minD; maxDims = maxD;</div><div class="line">        origin = <a name="a3"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">cv::Point</a>(0,0);</div><div class="line">        corner = <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">cv::Point</a>(0,0);</div><div class="line">        scale = 1.0;</div><div class="line">        rows = 0;</div><div class="line">        cols = 0;</div><div class="line">        setupQ = <span class="keyword">false</span>;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> stretch(<a name="_a4"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> <a name="a5"></a><a class="code" href="../../d7/dcc/group__core__utils__softfloat.html#gac48df53b8fd34b87e7b121fa8fd4c379">min</a>, <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> <a name="a6"></a><a class="code" href="../../d7/dcc/group__core__utils__softfloat.html#ga78f988f6cfa6223610298cbd4f86ec66">max</a>){</div><div class="line">        <span class="comment">// Stretch the canvas to include the points min and max.</span></div><div class="line">        <span class="keywordflow">if</span>(setupQ){</div><div class="line">            <span class="keywordflow">if</span>(corner.<a name="a7"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &lt; max.<a name="a8"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>){corner.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> = (int)(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> + 1.0);};</div><div class="line">            <span class="keywordflow">if</span>(corner.<a name="a9"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &lt; max.<a name="a10"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>){corner.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> = (int)(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> + 1.0);};</div><div class="line">            <span class="keywordflow">if</span>(origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &gt; min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>){origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> = (int) min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>;};</div><div class="line">            <span class="keywordflow">if</span>(origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &gt; min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>){origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> = (int) min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>;};</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">            origin = <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">cv::Point</a>((<span class="keywordtype">int</span>)min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, (<span class="keywordtype">int</span>)min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line">            corner = <a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">cv::Point</a>((<span class="keywordtype">int</span>)(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> + 1.0), (<span class="keywordtype">int</span>)(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> + 1.0));</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordtype">int</span> c = (int)(scale*((corner.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> + 1.0) - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>));</div><div class="line">        <span class="keywordflow">if</span>(c&lt;minDims){</div><div class="line">            scale = scale * (double)minDims/(<span class="keywordtype">double</span>)c;</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">            <span class="keywordflow">if</span>(c&gt;maxDims){</div><div class="line">                scale = scale * (double)maxDims/(<span class="keywordtype">double</span>)c;</div><div class="line">            }</div><div class="line">        }</div><div class="line">        <span class="keywordtype">int</span> r = (int)(scale*((corner.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> + 1.0) - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>));</div><div class="line">        <span class="keywordflow">if</span>(r&lt;minDims){</div><div class="line">            scale = scale * (double)minDims/(<span class="keywordtype">double</span>)r;</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">            <span class="keywordflow">if</span>(r&gt;maxDims){</div><div class="line">                scale = scale * (double)maxDims/(<span class="keywordtype">double</span>)r;</div><div class="line">            }</div><div class="line">        }</div><div class="line">        cols = (int)(scale*((corner.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> + 1.0) - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>));</div><div class="line">        rows = (int)(scale*((corner.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> + 1.0) - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>));</div><div class="line">        setupQ = <span class="keyword">true</span>;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> stretch(vector&lt;Point2f&gt; pts)</div><div class="line">    {   <span class="comment">// Stretch the canvas so all the points pts are on the canvas.</span></div><div class="line">        <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> min = pts[0];</div><div class="line">        <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> max = pts[0];</div><div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=1; i &lt; pts.size(); i++){</div><div class="line">            <a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point2f</a> pnt = pts[i];</div><div class="line">            <span class="keywordflow">if</span>(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &lt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>){max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>;};</div><div class="line">            <span class="keywordflow">if</span>(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &lt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>){max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>;};</div><div class="line">            <span class="keywordflow">if</span>(min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &gt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>){min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>;};</div><div class="line">            <span class="keywordflow">if</span>(min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &gt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>){min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>;};</div><div class="line">        };</div><div class="line">        stretch(min, max);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> stretch(<a name="_a11"></a><a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html">cv::RotatedRect</a> box)</div><div class="line">    {   <span class="comment">// Stretch the canvas so that the rectangle box is on the canvas.</span></div><div class="line">        <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> min = box.<a name="a12"></a><a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a60d492fbe1e457e2cdeac5160ed81422">center</a>;</div><div class="line">        <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> max = box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a60d492fbe1e457e2cdeac5160ed81422">center</a>;</div><div class="line">        <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> vtx[4];</div><div class="line">        box.<a name="a13"></a><a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a69d648b086f26dbce0029facae9bfb2d">points</a>(vtx);</div><div class="line">        <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; 4; i++ ){</div><div class="line">            <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a> pnt = vtx[i];</div><div class="line">            <span class="keywordflow">if</span>(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &lt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>){max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>;};</div><div class="line">            <span class="keywordflow">if</span>(max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &lt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>){max.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>;};</div><div class="line">            <span class="keywordflow">if</span>(min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &gt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>){min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>;};</div><div class="line">            <span class="keywordflow">if</span>(min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &gt; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>){min.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> = pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>;};</div><div class="line">        }</div><div class="line">        stretch(min, max);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> drawEllipseWithBox(<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html">cv::RotatedRect</a> box, <a name="_a14"></a><a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> color, <span class="keywordtype">int</span> lineThickness)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">if</span>(img.<a name="a15"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>()){</div><div class="line">            stretch(box);</div><div class="line">            img = <a name="a16"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a0b57b6a326c8876d944d188a46e0f556">cv::Mat::zeros</a>(rows,cols,<a name="a17"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga88c4cd9de76f678f33928ef1e3f96047">CV_8UC3</a>);</div><div class="line">        }</div><div class="line"></div><div class="line">        box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a60d492fbe1e457e2cdeac5160ed81422">center</a> = scale * <a name="a18"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga7d080aa40de011e4410bca63385ffe2a">cv::Point2f</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a60d492fbe1e457e2cdeac5160ed81422">center</a>.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a60d492fbe1e457e2cdeac5160ed81422">center</a>.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line">        box.<a name="a19"></a><a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a name="a20"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>  = (float)(scale * box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>);</div><div class="line">        box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a name="a21"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a> = (float)(scale * box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>);</div><div class="line"></div><div class="line">        <a name="a22"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga28b2267d35786f5f890ca167236cbc69">ellipse</a>(img, box, color, lineThickness, <a name="a23"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a85fdabe5335c9e6656563dfd7c94fb4f">LINE_AA</a>);</div><div class="line"></div><div class="line">        <a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point2f</a> vtx[4];</div><div class="line">        box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a69d648b086f26dbce0029facae9bfb2d">points</a>(vtx);</div><div class="line">        <span class="keywordflow">for</span>( <span class="keywordtype">int</span> j = 0; j &lt; 4; j++ ){</div><div class="line">            <a name="a24"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga7078a9fae8c7e7d13d24dac2520ae4a2">line</a>(img, vtx[j], vtx[(j+1)%4], color, lineThickness, <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a85fdabe5335c9e6656563dfd7c94fb4f">LINE_AA</a>);</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> drawPoints(vector&lt;Point2f&gt; pts, <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> color)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">if</span>(img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>()){</div><div class="line">            stretch(pts);</div><div class="line">            img = <a class="code" href="../../d3/d63/classcv_1_1Mat.html#a0b57b6a326c8876d944d188a46e0f556">cv::Mat::zeros</a>(rows,cols,<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga88c4cd9de76f678f33928ef1e3f96047">CV_8UC3</a>);</div><div class="line">        }</div><div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i &lt; pts.size(); i++){</div><div class="line">            <a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point2f</a> pnt = scale * <a class="code" href="../../dc/d84/group__core__basic.html#ga7d080aa40de011e4410bca63385ffe2a">cv::Point2f</a>(pts[i].x - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>, pts[i].y - origin.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>);</div><div class="line">            img.<a name="a25"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<a name="_a26"></a><a class="code" href="../../d6/dcf/classcv_1_1Vec.html">cv::Vec3b</a>&gt;(int(pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>), int(pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>))[0] = (<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>)color[0];</div><div class="line">            img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<a class="code" href="../../d6/dcf/classcv_1_1Vec.html">cv::Vec3b</a>&gt;(int(pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>), int(pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>))[1] = (<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>)color[1];</div><div class="line">            img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<a class="code" href="../../d6/dcf/classcv_1_1Vec.html">cv::Vec3b</a>&gt;(int(pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a>), int(pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a>))[2] = (<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>)color[2];</div><div class="line">        };</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">void</span> drawLabels( std::vector&lt;std::string&gt; text, std::vector&lt;cv::Scalar&gt; colors)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">if</span>(img.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abbec3525a852e77998aba034813fded4">empty</a>()){</div><div class="line">            img = <a class="code" href="../../d3/d63/classcv_1_1Mat.html#a0b57b6a326c8876d944d188a46e0f556">cv::Mat::zeros</a>(rows,cols,<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga88c4cd9de76f678f33928ef1e3f96047">CV_8UC3</a>);</div><div class="line">        }</div><div class="line">        <span class="keywordtype">int</span> vPos = 0;</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i=0; i &lt; text.size(); i++) {</div><div class="line">            <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> color = colors[i];</div><div class="line">            std::string txt = text[i];</div><div class="line">            <a name="_a27"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> textsize = <a name="a28"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga3d2abfcb995fd2db908c8288199dba82">getTextSize</a>(txt, <a name="a29"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11af7b1b25521fc9b5731a97cfd13460c2a">FONT_HERSHEY_COMPLEX</a>, 1, 1, 0);</div><div class="line">            vPos += (int)(1.3 * textsize.<a name="a30"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>);</div><div class="line">            <a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point</a> org((img.<a name="a31"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> - textsize.<a name="a32"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>), vPos);</div><div class="line">            <a name="a33"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576">cv::putText</a>(img, txt, org, <a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11af7b1b25521fc9b5731a97cfd13460c2a">FONT_HERSHEY_COMPLEX</a>, 1, color, 1, <a name="a34"></a><a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a5d32eda7017db273a37f158e5b51442a">LINE_8</a>);</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> help(<span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;\nThis program is demonstration for ellipse fitting. The program finds\n&quot;</span></div><div class="line">            <span class="stringliteral">&quot;contours and approximate it by ellipses. Three methods are used to find the \n&quot;</span></div><div class="line">            <span class="stringliteral">&quot;elliptical fits: fitEllipse, fitEllipseAMS and fitEllipseDirect.\n&quot;</span></div><div class="line">            <span class="stringliteral">&quot;Call:\n&quot;</span></div><div class="line">        &lt;&lt; argv[0] &lt;&lt; <span class="stringliteral">&quot; [image_name -- Default ellipses.jpg]\n&quot;</span> &lt;&lt; endl;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> sliderPos = 70;</div><div class="line"></div><div class="line"><a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> image;</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> fitEllipseQ, fitEllipseAMSQ, fitEllipseDirectQ;</div><div class="line"><a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> fitEllipseColor       = <a name="a35"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255,  0,  0);</div><div class="line"><a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> fitEllipseAMSColor    = <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(  0,255,  0);</div><div class="line"><a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> fitEllipseDirectColor = <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(  0,  0,255);</div><div class="line"><a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a> fitEllipseTrueColor   = <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(255,255,255);</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> processImage(<span class="keywordtype">int</span>, <span class="keywordtype">void</span>*);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv )</div><div class="line">{</div><div class="line">    fitEllipseQ       = <span class="keyword">true</span>;</div><div class="line">    fitEllipseAMSQ    = <span class="keyword">true</span>;</div><div class="line">    fitEllipseDirectQ = <span class="keyword">true</span>;</div><div class="line"></div><div class="line">    <a name="_a36"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">cv::CommandLineParser</a> parser(argc, argv,<span class="stringliteral">&quot;{help h||}{@image|ellipses.jpg|}&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span> (parser.<a name="a37"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a8c41cf242b2ad8c0472e3b57893ef200">has</a>(<span class="stringliteral">&quot;help&quot;</span>))</div><div class="line">    {</div><div class="line">        help(argv);</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">    }</div><div class="line">    <span class="keywordtype">string</span> filename = parser.<a name="a38"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;@image&quot;</span>);</div><div class="line">    image = <a name="a39"></a><a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(<a name="a40"></a><a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>(filename), 0);</div><div class="line">    <span class="keywordflow">if</span>( image.empty() )</div><div class="line">    {</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Couldn&#39;t open image &quot;</span> &lt;&lt; filename &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">    }</div><div class="line"></div><div class="line">    <a name="a41"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;source&quot;</span>, image);</div><div class="line">    <a name="a42"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow</a>(<span class="stringliteral">&quot;result&quot;</span>, <a name="a43"></a><a class="code" href="../../d0/d90/group__highgui__window__flags.html#ggabf7d2c5625bc59ac130287f925557ac3a29e45c5af696f73ce5e153601e5ca0f1">WINDOW_NORMAL</a> );</div><div class="line"></div><div class="line">    <span class="comment">// Create toolbars. HighGUI use.</span></div><div class="line">    <a name="a44"></a><a class="code" href="../../d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b">createTrackbar</a>( <span class="stringliteral">&quot;threshold&quot;</span>, <span class="stringliteral">&quot;result&quot;</span>, &amp;sliderPos, 255, processImage );</div><div class="line"></div><div class="line">    processImage(0, 0);</div><div class="line"></div><div class="line">    <span class="comment">// Wait for a key stroke; the same function arranges events processing</span></div><div class="line">    <a name="a45"></a><a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>();</div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Define trackbar callback function. This function finds contours,</span></div><div class="line"><span class="comment">// draws them, and approximates by ellipses.</span></div><div class="line"><span class="keywordtype">void</span> processImage(<span class="keywordtype">int</span> <span class="comment">/*h*/</span>, <span class="keywordtype">void</span>*)</div><div class="line">{</div><div class="line">    <a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html">RotatedRect</a> box, boxAMS, boxDirect;</div><div class="line">    vector&lt;vector&lt;Point&gt; &gt; contours;</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> bimage = image &gt;= sliderPos;</div><div class="line"></div><div class="line">    <a name="a46"></a><a class="code" href="../../d3/dc0/group__imgproc__shape.html#gadf1ad6a0b82947fa1fe3c3d497f260e0">findContours</a>(bimage, contours, <a name="a47"></a><a class="code" href="../../d3/dc0/group__imgproc__shape.html#gga819779b9857cc2f8601e6526a3a5bc71a48b9c2cb1056f775ae50bb68288b875e">RETR_LIST</a>, <a name="a48"></a><a class="code" href="../../d3/dc0/group__imgproc__shape.html#gga4303f45752694956374734a03c54d5ffaf7d9a3582d021d5dadcb0e37201a62f8">CHAIN_APPROX_NONE</a>);</div><div class="line"></div><div class="line">    canvas paper;</div><div class="line">    paper.init(<span class="keywordtype">int</span>(0.8*<a name="a49"></a><a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(bimage.<a name="a50"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>, bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>)), <span class="keywordtype">int</span>(1.2*<a name="a51"></a><a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>, bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>)));</div><div class="line">    paper.stretch(<a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a>(0.0f, 0.0f), <a class="code" href="../../db/d4e/classcv_1_1Point__.html">cv::Point2f</a>((<span class="keywordtype">float</span>)(bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>+2.0), (<span class="keywordtype">float</span>)(bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>+2.0)));</div><div class="line"></div><div class="line">    std::vector&lt;std::string&gt; text;</div><div class="line">    std::vector&lt;cv::Scalar&gt; color;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (fitEllipseQ) {</div><div class="line">        text.push_back(<span class="stringliteral">&quot;OpenCV&quot;</span>);</div><div class="line">        color.push_back(fitEllipseColor);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> (fitEllipseAMSQ) {</div><div class="line">        text.push_back(<span class="stringliteral">&quot;AMS&quot;</span>);</div><div class="line">        color.push_back(fitEllipseAMSColor);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> (fitEllipseDirectQ) {</div><div class="line">        text.push_back(<span class="stringliteral">&quot;Direct&quot;</span>);</div><div class="line">        color.push_back(fitEllipseDirectColor);</div><div class="line">    }</div><div class="line">    paper.drawLabels(text, color);</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> margin = 2;</div><div class="line">    vector&lt; vector&lt;Point2f&gt; &gt; points;</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i = 0; i &lt; contours.size(); i++)</div><div class="line">    {</div><div class="line">        <span class="keywordtype">size_t</span> count = contours[i].size();</div><div class="line">        <span class="keywordflow">if</span>( count &lt; 6 )</div><div class="line">            <span class="keywordflow">continue</span>;</div><div class="line"></div><div class="line">        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> pointsf;</div><div class="line">        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(contours[i]).<a name="a52"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(pointsf, <a name="a53"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4a3def5d72b74bed31f5f8ab7676099c">CV_32F</a>);</div><div class="line"></div><div class="line">        vector&lt;Point2f&gt;pts;</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; pointsf.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>; j++) {</div><div class="line">            <a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point2f</a> pnt = <a class="code" href="../../dc/d84/group__core__basic.html#ga7d080aa40de011e4410bca63385ffe2a">Point2f</a>(pointsf.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">float</span>&gt;(j,0), pointsf.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">float</span>&gt;(j,1));</div><div class="line">            <span class="keywordflow">if</span> ((pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &gt; margin &amp;&amp; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &gt; margin &amp;&amp; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a4c96fa7bdbfe390be5ed356edb274ff3">x</a> &lt; bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>-margin &amp;&amp; pnt.<a class="code" href="../../db/d4e/classcv_1_1Point__.html#a157337197338ff199e5df1a393022f15">y</a> &lt; bimage.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>-margin)) {</div><div class="line">                <span class="keywordflow">if</span>(j%20==0){</div><div class="line">                    pts.push_back(pnt);</div><div class="line">                }</div><div class="line">            }</div><div class="line">        }</div><div class="line">        points.push_back(pts);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i = 0; i &lt; points.size(); i++)</div><div class="line">    {</div><div class="line">        vector&lt;Point2f&gt; pts = points[i];</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (pts.size()&lt;=5) {</div><div class="line">            <span class="keywordflow">continue</span>;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (fitEllipseQ) {</div><div class="line">            box = <a name="a54"></a><a class="code" href="../../d3/dc0/group__imgproc__shape.html#gaf259efaad93098103d6c27b9e4900ffa">fitEllipse</a>(pts);</div><div class="line">            <span class="keywordflow">if</span>( <a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &gt; <a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>)*30 ||</div><div class="line">               <a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &lt;= 0 ||</div><div class="line">               <a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &lt;= 0){<span class="keywordflow">continue</span>;};</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (fitEllipseAMSQ) {</div><div class="line">            boxAMS = <a name="a55"></a><a class="code" href="../../d3/dc0/group__imgproc__shape.html#ga69e90cda55c4e192a8caa0b99c3e4550">fitEllipseAMS</a>(pts);</div><div class="line">            <span class="keywordflow">if</span>( <a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(boxAMS.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, boxAMS.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &gt; <a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(boxAMS.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, boxAMS.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>)*30 ||</div><div class="line">               <a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &lt;= 0 ||</div><div class="line">               <a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &lt;= 0){<span class="keywordflow">continue</span>;};</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (fitEllipseDirectQ) {</div><div class="line">            boxDirect = <a name="a56"></a><a class="code" href="../../d3/dc0/group__imgproc__shape.html#ga6421884fd411923a74891998bbe9e813">fitEllipseDirect</a>(pts);</div><div class="line">            <span class="keywordflow">if</span>( <a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(boxDirect.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, boxDirect.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &gt; <a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(boxDirect.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, boxDirect.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>)*30 ||</div><div class="line">               <a class="code" href="../../db/de0/group__core__utils.html#gafa99ec4acc4ecb2dc3c2d05da15d0e3f">MAX</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &lt;= 0 ||</div><div class="line">               <a class="code" href="../../db/de0/group__core__utils.html#ga3acffbd305ee72dcd4593c0d8af64a4f">MIN</a>(box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>, box.<a class="code" href="../../db/dd6/classcv_1_1RotatedRect.html#a68ac6414ed3233245175e2c4f3b2bbfb">size</a>.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>) &lt;= 0 ){<span class="keywordflow">continue</span>;};</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (fitEllipseQ) {</div><div class="line">            paper.drawEllipseWithBox(box, fitEllipseColor, 3);</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (fitEllipseAMSQ) {</div><div class="line">            paper.drawEllipseWithBox(boxAMS, fitEllipseAMSColor, 2);</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (fitEllipseDirectQ) {</div><div class="line">            paper.drawEllipseWithBox(boxDirect, fitEllipseDirectColor, 1);</div><div class="line">        }</div><div class="line"></div><div class="line">        paper.drawPoints(pts, <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a>(255,255,255));</div><div class="line">    }</div><div class="line"></div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;result&quot;</span>, paper.img);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:29 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
